package com.stm.bi.etl.demo;

import com.stm.bi.enums.DateType;
import com.stm.bi.etl.AbstractDataEtlTask;
import com.stm.bi.jdbc.DataSourceEnum;
import com.stm.framework.core.util.FileResourceLoader;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Author chenyingjun
 * @Desc
 * @Date 2025/2/11 11:22
 */
@Component
public class DemoDataEtlTask extends AbstractDataEtlTask {

    @Override
    public List<DateType> getEtlDateTypes() {
        return Arrays.asList(DateType.YEAR,DateType.MONTH);
    }

    @Override
    public List<Map> extract(Long orgId, String orgNo, DateType dateType, LocalDateTime startDateTime, LocalDateTime endDateTime) {
        String selectSql = FileResourceLoader.getResourceAsString("/sql/demo.sql");
        log.info("SQL查询：{}",selectSql);
        List<Map> list = jdbcService.selectList(selectSql,new Object[]{orgId,startDateTime.getYear()});
        return list;
    }

    @Override
    public List<Map> transform(Long orgId, String orgNo, List<Map> dataList) {
        return dataList;
    }

    @Override
    public void load(Long orgId, String orgNo, List<Map> dataList) {
        dorisLoadRepository.putLoad("ads_res_material_style_category_year",dataList);
    }


    @Override
    public boolean isTenantLine() {
        return true;
    }

    @Override
    public boolean syncWithTimeRange() {
        return true;
    }

    @Override
    public String getTaskName() {
        return "ETL演示";
    }


    @Override
    public int getDelayDays() {
        return 0;
    }
}
